<template>
  <div>
    <i
      class="iconfont"
      :class="isFullscreen ? 'icon-exit-fullscreen' : 'icon-full_screen'"
      @click="click"
    ></i>
  </div>
</template>

<script>
// 屏幕大屏插件
import screenfull from "screenfull";

export default {
  name: "sScreenfull",
  data() {
    return {
      isFullscreen: false
    };
  },
  mounted() {
    this.init();
  },
  beforeUnmount() {
    this.destroy();
  },
  methods: {
    click() {
      if (!screenfull.isEnabled) {
        this.$message({
          message: "您的浏览器不支持放大！",
          type: "warning"
        });
        return false;
      }
      screenfull.toggle();
    },
    change() {
      this.isFullscreen = screenfull.isFullscreen;
    },
    init() {
      if (screenfull.enabled) {
        screenfull.on("change", this.change);
      }
    },
    destroy() {
      if (screenfull.enabled) {
        screenfull.off("change", this.change);
      }
    }
  }
};
</script>

<style lang="scss" scoped>
@import "s-screenfull.scss";
</style>
